
class Solution {
public:
    int maxRepeating(string sequence, string word) {
        // int length1 = sequence.length();
        // int length2 = word.length();
        // int ptr1 = 0,ptr2 = 0;
        // int maxK = INT_MIN;
        // while(ptr1 < length1)
        // {
        //     int tmp1 = ptr1;
        //     int tmp_k = 0;
        //     while(tmp1 < length1 && sequence[tmp1] == word[ptr2])
        //     {
        //         while(tmp1 < length1 && ptr2 < length2)
        //         {
        //             if(sequence[tmp1] != word[ptr2]){
        //                 goto end;
        //             }
        //             ++ptr2;
        //             ++tmp1;
        //         }
        //         if(ptr2 == length2)
        //         tmp_k++;
        //         ptr2 = 0;
        //     }
        //     end:
        //     maxK = std::max(maxK,tmp_k);
        //     ptr2 = 0;
        //     sequence[tmp1] == word[ptr2] ? ptr1 = tmp1 : ++ptr1;
        // }
        // return maxK;

        int length1 = sequence.length();
        int length2 = word.length();
        if(length1 <  length2){
            return 0;
        }
        vector<int> dp(length1,0);
        for(int i = length2-1;i < length1;++i)
        {
            bool valid = true;
            int start_pos = i - length2 + 1;
            for(int j = 0;j < length2;++j)
            {
                if(sequence[start_pos + j] != word[j]){
                    valid = false;
                    break;
                }
            }
            if(valid){
                dp[i] = (i == length2-1 ? 0 : dp[i-length2]) + 1;
            }
        }
        return *std::max_element(dp.begin(),dp.end());
    }
};